﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using models;

namespace DAL
{
    public class PayService
    {
        //购买信息详情表
        //public SqlDataReader get(Pay pay)
        //{
        //    string sql = string.Format("select count(d.price) from pay p,product d,[User] u where p.proid=d.id and p.userid=u.id and p.userid=u.id group by d.price,d.proname");
        //    return DBhelper.DataReader(sql);
        //}
        //查询用户的进行付款的订单 (显示出未付款的订单 且是当前订单号)
        public SqlDataReader SelPay(string id ,string ddh) 
        {
            string sql = string.Format("select  [count]* p.Price uSum,c.[Count],p.Id,p.ProName,p.Pic,Speci,Price ,s.Id,s .storeName,u.Id,u.Uid,c.Batch  from pay c join store s on c.StoreID = s.Id join[User] u on c.UserId = u.Id join product p on c.ProID = p.Id join [order] o on o.Orders=c.Batch where u.Id='{0}' and o.State=1 and c.Batch='{1}'", id,ddh);
            return DBhelper.DataReader(sql);
        }
        //新增购买详情
        public bool add(Pay pay)
        {
            string sql = string.Format("insert pay values('{0}','{1}','{2}','{3}','{4}','{5}')",pay.Sum,pay.Count,pay.Userid,pay.Storeid,pay.Proid,pay.Batch);
            return DBhelper.ex(sql);
        }
        //全部总价显示（未支付的）
        public SqlDataReader SumCart(string id ,string ddh)
        {
            string sql = string.Format("select sum([sum]) from pay where Userid='{0}' and Batch='{1}'", id, ddh);
            return DBhelper.DataReader(sql);
        }
    }
}
